//
//  UIPickerTextViewController.m
//  ZBTechniqueLibrary
//
//  Created by apple on 2018/10/8.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "UIPickerTextViewController.h"
#import "ZBPickerView.h"

@interface UIPickerTextViewController () <ZBPickerViewDataSource,UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong)  ZBPickerView *pickerView;

@property (nonatomic, strong)  NSMutableArray *dataList;

@property (nonatomic, strong) UITableView *tableView;
@end

@implementation UIPickerTextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
   
    
}


#pragma mark - tableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if(indexPath.row < self.dataList.count){
      NSString *title =  self.dataList[indexPath.row];
        cell.textLabel.text = title;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
            {
                [ZBPickerView showPickerViewDefaultConfigWithType:ZBPickerValueType_sex compeletion:^(NSInteger row, NSInteger component, NSString *selectString) {
                    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                    cell.detailTextLabel.text = selectString;
                }];
            }
            break;
        case 1:
            {
                [ZBPickerView showPickerViewDefaultConfigWithType:ZBPickerValueType_yyyymmdd compeletion:^(NSInteger row, NSInteger component, NSString *selectString) {
                    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                    cell.detailTextLabel.text = selectString;
                }];
            }
            break;
        case 2:
        {
            [ZBPickerView showPickerViewDefaultConfigWithType:ZBPickerValueType_hhmmss compeletion:^(NSInteger row, NSInteger component, NSString *selectString) {
                UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                cell.detailTextLabel.text = selectString;
            }];
        }
            break;
        case 3:
        {
            [ZBPickerView showPickerViewDefaultConfigWithType:ZBPickerValueType_city compeletion:^(NSInteger row, NSInteger component, NSString *selectString) {
                UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                cell.detailTextLabel.text = selectString;
            }];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - lazy
- (ZBPickerView *)pickerView
{
    if(_pickerView == nil)
    {
        _pickerView = [[ZBPickerView alloc]init];
        _pickerView.dataSouce = self;
    }
    return _pickerView;
}
- (UITableView *)tableView
{
    if(_tableView == nil)
    {
        _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
    }
    return _tableView;
}

- (NSMutableArray *)dataList
{
    if(_dataList == nil)
    {
        _dataList = [NSMutableArray array];
        [_dataList addObject:@"性别"];
        [_dataList addObject:@"年月日"];
        [_dataList addObject:@"时分秒"];
        [_dataList addObject:@"城市选择"];
    }
    return _dataList;
}

@end
